package com.knowif.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.knowif.dao.CommentPictureMapper;
import com.knowif.pojo.CommentPicture;
import com.knowif.pojo.CommentPictureExample;
import com.knowif.util.commonUtil.IntegerUtil;

@Service
public class CommentPicture_service {
	
	@Autowired
	private CommentPictureMapper commentPictureMapper;
	
	
	public List<CommentPicture> getByCommentIds(List<Integer> userCommentIds){
		if(userCommentIds == null ||userCommentIds.isEmpty()){
			return new ArrayList<CommentPicture>();
		}
		CommentPictureExample commentPictureExample = new CommentPictureExample();
		commentPictureExample.createCriteria().andOrderCommentIdIn(userCommentIds);
		List<CommentPicture> commentPictures = commentPictureMapper.selectByExample(commentPictureExample);
		return commentPictures;
	}
	
	public int insert(CommentPicture record){
		if(record == null){
			return 0;
		}
		return commentPictureMapper.insert(record);
	}
	
	
	public int insertAll(List<CommentPicture> commentPictures){
		if(commentPictures == null || commentPictures.isEmpty()){
			return 0;
		}
		int insertNum = 0;
		for(CommentPicture commentPicture :commentPictures){
			insertNum += insert(commentPicture);
		}
		return insertNum;
	}
	
	
	public int insertAll(List<CommentPicture> commentPictures,Integer commentId){
		if(commentPictures == null || commentPictures.isEmpty()){
			return 0;
		}
		if(IntegerUtil.isEmpty(commentId)){
			return 0;
		}
		int insertNum = 0;
		for(CommentPicture commentPicture :commentPictures){
			commentPicture.setOrderCommentId(commentId);
			insertNum += insert(commentPicture);
		}
		return insertNum;
	}
	
	public int deleteByCommentIds(Integer userCommentId){
		if(userCommentId == null){
			return 0;
		}
		CommentPictureExample commentPictureExample = new CommentPictureExample();
		commentPictureExample.createCriteria().andOrderCommentIdEqualTo(userCommentId);
		return commentPictureMapper.deleteByExample(commentPictureExample);
	}
}










